package com.ruoyi.system.service.impl;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WxJumpMapper;
import com.ruoyi.system.domain.WxJump;
import com.ruoyi.system.service.IWxJumpService;

/**
 * 微信跳转，生成链接Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-24
 */
@Service
public class WxJumpServiceImpl implements IWxJumpService
{
    @Autowired
    private WxJumpMapper wxJumpMapper;

    /**
     * 查询微信跳转，生成链接
     *
     * @param id 微信跳转，生成链接主键
     * @return 微信跳转，生成链接
     */
    @Override
    public WxJump selectWxJumpById(Long id)
    {
        return wxJumpMapper.selectWxJumpById(id);
    }

    /**
     * 查询微信跳转，生成链接列表
     *
     * @param wxJump 微信跳转，生成链接
     * @return 微信跳转，生成链接
     */
    @Override
    public List<WxJump> selectWxJumpList(WxJump wxJump)
    {
        return wxJumpMapper.selectWxJumpList(wxJump);
    }

    /**
     * 新增微信跳转，生成链接
     *
     * @param wxJump 微信跳转，生成链接
     * @return 结果
     */
    @Override
    public int insertWxJump(WxJump wxJump)
    {
        String encodedString = Base64.getEncoder().encodeToString(wxJump.getPicUrl().getBytes(StandardCharsets.UTF_8));
        System.out.println("Encoded String: " + encodedString);

        // 解码
        byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
        String decodedString = new String(decodedBytes);
        System.out.println("Decoded String: " + decodedString);
        wxJump.setUuid(IdUtils.fastSimpleUUID());
        wxJump.setPassUrl(encodedString);

        return wxJumpMapper.insertWxJump(wxJump);
    }

    /**
     * 修改微信跳转，生成链接
     *
     * @param wxJump 微信跳转，生成链接
     * @return 结果
     */
    @Override
    public int updateWxJump(WxJump wxJump)
    {
        return wxJumpMapper.updateWxJump(wxJump);
    }

    /**
     * 批量删除微信跳转，生成链接
     *
     * @param ids 需要删除的微信跳转，生成链接主键
     * @return 结果
     */
    @Override
    public int deleteWxJumpByIds(Long[] ids)
    {
        return wxJumpMapper.deleteWxJumpByIds(ids);
    }

    /**
     * 删除微信跳转，生成链接信息
     *
     * @param id 微信跳转，生成链接主键
     * @return 结果
     */
    @Override
    public int deleteWxJumpById(Long id)
    {
        return wxJumpMapper.deleteWxJumpById(id);
    }
}
